<?php
include 'sysco.function.php';


$con = mysql_connect($HOST, $USER, $PASS);
mysql_select_db($DB);

$menuProdCountArr = array('lp000051383792' => 506, 'lp000051396857' => 292, 'lpLaVigaRwc' => 121);
$menuProdCount = $menuProdCountArr[$MERCHANT];
/************************/
echo $MERCHANT."\n";
$order = 'TOTAL';
$totSale = getAllOrderCount($MERCHANT);
$dataTopTwBySalesCount = topTwenty($MERCHANT, $order, 10000);
$tot80 = $totSale['TOTAL']*0.8;

$i = 1;
$tot = 0;
foreach ($dataTopTwBySalesCount as $data) {
  $tot+= $data['TOTAL'];
  if ($tot > $tot80) {
    
    break;
  }
  $i++;
}
echo $order .' - - '.$menuProdCount.' = '.$tot.' = '.$totSale['TOTAL'].' - ';
echo $i.' Items (='.round(($i/$menuProdCount)*100).' of total items) contributed '.round(($tot/$totSale['TOTAL'])*100).'% of revenues';
echo "\n";
///

$order = 'TOTAL_SALE_COUNT';
$count80 = $totSale['TOTAL_SALE_COUNT']*0.8;
$dataTopTwBySalesCount = topTwenty($MERCHANT, $order, 10000);

$i = 1;
$tot = 0;
foreach ($dataTopTwBySalesCount as $data) {
  $tot+= $data['TOTAL_SALE_COUNT'];
  if ($tot > $count80) {
    
    break;
  }
  $i++;
}
echo $order .' - - '.$menuProdCount.' = '.$tot.' = '.$totSale['TOTAL_SALE_COUNT'].' - ';
echo $i.' Items (='.round(($i/$menuProdCount)*100).' of total items) contributed '.round(($tot/$totSale['TOTAL_SALE_COUNT'])*100).'% of sales volume';
echo "\n";
DIE();

/************************************/

if ($month == 1) {
  $_SESSION['from'] = '2013-01-01 03:00:00';
  $_SESSION['to']   = '2013-02-01 02:59:00';
} else if ($month == 2) {
  $_SESSION['from'] = '2013-02-01 03:00:00';
  $_SESSION['to']   = '2013-03-01 02:59:00';
}
$noOrdersItems = getNoSoldItems($MERCHANT);
$prodCount = 0;
$tmpArr = array();
foreach ($noOrdersItems as $noOrdersItem) {
  if (!isset($tmpArr[$noOrdersItem['PRODUCT_ID']])) {
    $tmpArr[$noOrdersItem['PRODUCT_ID']] = 1;
    $prodCount++;
  }
}
echo $prodCount. ' Items (='.(($prodCount/$menuProdCount)*100).') did not sell during the selected period'."\n";

if ($month == 1) {
  $_SESSION['from'] = '2012-12-01 03:00:00';
  $_SESSION['to']   = '2013-02-01 02:59:00';
} else if ($month == 2) {
  $_SESSION['from'] = '2013-01-31 03:00:00';
  $_SESSION['to']   = '2013-03-01 02:59:00';
}
$noOrdersItems = getNoSoldItems($MERCHANT);
$prodCount = 0;
$tmpArr = array();
foreach ($noOrdersItems as $noOrdersItem) {
  if (!isset($tmpArr[$noOrdersItem['PRODUCT_ID']])) {
    $tmpArr[$noOrdersItem['PRODUCT_ID']] = 1;
    $prodCount++;
  }
}
echo $prodCount. ' Items (='.(($prodCount/$menuProdCount)*100).') did not sell in the last 60 days';


?>
